package com.floreantpos.ui.report;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.data.JRTableModelDataSource;
import net.sf.jasperreports.engine.util.JRLoader;
import net.sf.jasperreports.view.JRViewer;

import com.floreantpos.model.StoreItemCompare;
import com.floreantpos.model.dao.StoreItemRelDAO;
import com.floreantpos.report.StoreItemCompareReportModel;
import com.floreantpos.report.services.ReportService;
import com.floreantpos.util.Util;

public class StoreItemCompareReport extends Report {

	public StoreItemCompareReport() {
		super();
	}

	@Override
	public void refresh() throws Exception {
		try{
			Date fromDate = getStartDate();
			Date toDate = getEndDate();
			
			List<StoreItemCompare> data = StoreItemRelDAO.getInstance().findAllCompareData(fromDate, toDate);
			StoreItemCompareReportModel reportModel = new StoreItemCompareReportModel();
			reportModel.setItems(data);
			
			HashMap map = new HashMap();
			ReportUtil.populateRestaurantProperties(map);
			map.put("reportTitle", "============================ 材料消耗对照表 =============================");
//			map.put("reportTime", ReportService.formatFullDate(new Date()));
			map.put("reportTime", Util.formatDateTime(fromDate) + " ~ " + Util.formatDateTime(toDate));
//			map.put("terminalName", com.floreantpos.POSConstants.ALL);
			
			JasperReport masterReport = (JasperReport) JRLoader.loadObject(StoreItemCompareReport.class.getResource("/com/floreantpos/ui/report/store_item_compare_report.jasper"));
			JasperPrint print = JasperFillManager.fillReport(masterReport, map, new JRTableModelDataSource(reportModel));
			viewer = new JRViewer(print);
		}catch(Exception e){
			e.printStackTrace();
		}
	}

	@Override
	public boolean isDateRangeSupported() {
		return true;
	}

	@Override
	public boolean isTypeSupported() {
		return false;
	}

}
